package com.hxy.springcloud.controller;

import com.hxy.springcloud.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DepartmentController {

    @Autowired
    private RestTemplate restTemplate;

    //通过ribbon来访问时，这里地址应该是一个变量
    //private String PROVIDER_URL = "http://localhost:8001";
    private String PROVIDER_URL = "http://SPRINGCLOUD-PROVIDER-DEPARTMENT";

    @PostMapping("/consume/dept/add")
    public boolean addDepartment(Department department) {
        return true;
    }

    @RequestMapping("/consume/dept/queryById/{id}")
    public Department queryDepartmentById(@PathVariable("id") long id) {
        return restTemplate.getForObject(PROVIDER_URL + "/dept/queryById/" + id, Department.class);
    }

    @RequestMapping("/consume/dept/queryAll")
    public List<Department> queryAllDepartment() {
        return restTemplate.getForObject(PROVIDER_URL + "/dept/queryAll", List.class);
    }
}
